<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>问题选项</title>
    <link rel="stylesheet" type="text/css" href="../../themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../css/default.css">
    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../../js/datagrid-detailview.js"></script>
    <script type="text/javascript" src="../../js/datagrid-cellediting.js"></script>
    <script type="text/javascript" src="../../js/jquery-form.js"></script>
    <script type="text/javascript" src="../../js/app.js"></script>
    <script type="text/javascript" src="../../js/common.js"></script>
    <script type="text/javascript" src="../../js/comm_check.js"></script>
    <script type="text/javascript" src="../../js/relax_function.js"></script>
    

</head>
<body>
    <!-- 用户信息 -->
    <table  id="dg_cr" class="easyui-datagrid">
    </table>
    
<!-- 工具栏 -->
<div id="toolbar">
	    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="addQuestionOption()" >新增</a>
	     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteQuestionOption()" >删除</a>
		<!--进度条-->
		<div id="div_pb" style="position: absolute; width: 400px; height: 50px; right: 20%; left: 25%; top: 35%; bottom: 20%; margin-left: 50px; margin-top: 25px; display: none; text-align: center;">
	    	<img src="../../images/loading.gif" />
		</div>
</div>

<!-- 弹出窗口定义 编辑信息 -->
	<div id="tanchuang" class="easyui-dialog" title="编辑 信息" data-options="iconCls:'icon-edit'" closed="true" style="width:500px;height:350px;padding:10px;align-content: true">
		<form id="fm" method="post">
	    	<input name="id" id="id" type='hidden'/>
	        <table class="searchTable">
	            <tr>
	             <tr>
	                <td >答案序号:</td>
	                <td><input class="easyui-validatebox" type="text" id="optionId" style="width:200px;" name="optionId" data-options="required:true"/></td>
	              </tr>
				  <tr>
	                <td >选项描述:</td>
	                <td><input class="easyui-validatebox" type="text" id="optionDesc" style="width:200px;" name="optionDesc" data-options="required:true"/></td>
	              </tr>
	              <tr>
	                <td >是否正确:</td>
	                <td>
	                 <input  type = "radio"  name="isCorrect"  value = "0"  checked = "checked"/>否
                     <input  type = "radio"  name="isCorrect"  value = "1" />是
                    </td>
	           	 <tr>
				<tr>
	                <td colspan="2" align="center">
	                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveOrUpdInfo()">确定</a>
	                </td>
	            </tr>
	        </table>
	    </form>

	</div>
    <script type="text/javascript">
    	
    	var questionId='';
    	var Request = GetRequest();
			if(Request["questionId"]){
				questionId = Request["questionId"].split("%")[0];
			}
    	var size = 10;
    	var page = 1;
        var conf = {
              options: {
                singleSelect: false,
                ctrlSelect: true,
                showFooter: true,
                fit: true,
                fitColumns: true,
                checkOnSelect: false,
                selectOnCheck: false,
                footer: '#toolbar',
                striped: true,
                columns: [[
                    {field: 'ck', checkbox: true},
                    {field: 'id', title: 'id',  align: 'left', halign: 'center',hidden:true},
                    {field: 'questionId', title: '问题id',  align: 'left', halign: 'center',hidden:true},
                    {field: 'optionId', title: '答案序号',  align: 'left', halign: 'center'},
                    {field: 'optionDesc', title: '选项描述',  align: 'left', halign: 'center'},
                    {field: 'isCorrect', title: '是否正确答案',  align: 'left', halign: 'center',
                    	formatter: function(value, row, index) {
                            if(value == '0') {
                            	var valueName="否";
                            	return '<font color="blue">' + valueName + '</font>';
                            } 
                            if(value == '1') {
                            	var valueName="是";
                            	return '<font color="red">' + valueName + '</font>';
                            }
                        }   
                    }
                    
                ]],
                pagination: true,
                pageSize: size,
                pageList: [size * 1, size * 2, size * 3, size * 5],
                pageNumber: 1,
                rownumbers: true,
                onAfterEdit: function (rowIndex, rowData, changes) {
                },
                rowStyler: function (index, row) {
                },
                onDblClickRow:onDbClick
            }
        }; 
        $(function () {
            $('#pb').progressbar({
                onChange: function (value) {
                    $('.progressbar-value').css('background-color', 'red');
                }
            });
            $('#dg_cr').datagrid({footer: '#toolbar'}).datagrid('subgrid', conf);
            loadOptionPage(page, size);
            $('#dg_cr').datagrid('getPager').pagination({
                loadMsg: '正在加载数据...',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
                onSelectPage: function (page, size) {
                	loadOptionPage(page, size);

                }
            });
        });
        function loadOptionPage(page,size) {
        	page = page || 1;
            size = size || 10;
        	var id = questionId;
            $('#dg_cr').datagrid("loading");
            var service = $.svc.getSVC("/examManager/getQuestionOptionsPage");
            service.setPage(page, size)
            .setParam("questionId", id);
            service.call(
                    function (response, status) {
                        if (response.getResult().length == '0') {
                            $('#dg_cr').datagrid("loadData", []);
                        } else {
                            $('#dg_cr').datagrid("loadData", response.getResult());
                        }
                        $('#dg_cr').datagrid("loaded");
                    });
        }
        //重置
        $('#resetSearch').click(function(){
        	$('#userTypeSerch').combobox('setValue','');
        	loadOptionPage();
        })
          //添加按钮
        function addQuestionOption(){
          $('#fm input').removeAttr("disabled");
          $('#fm').form('reset');
          document.getElementById("id").value="";
      	  $('#tanchuang').dialog('open').dialog('setTitle','添加');
		 
        }
     // 双击打开窗口（修改）
    	  function onDbClick(rowIndex, rowData) {
    		$('#fm').form('reset');
    		  obj = null;
    		  if (rowData){
    			$('#fm input').removeAttr("disabled");
    			$('#tanchuang').dialog('open').dialog('setTitle','编辑');
            	$('#fm').form('load',rowData);
    	          obj = rowData;
    	          if(!obj)obj = new Object();
    	          //为页面赋值
    	          $('#fm').form('load',obj);
    	      }
    	  }
        // 编辑框 确定按钮
        function saveOrUpdInfo(){
          var optionDesc = $('#optionDesc').val();
          var optionId = $('#optionId').val();
          var isCorrect = $("input[name='isCorrect']:checked").val();
          var id = $('#id').val();
     	  var service = $.svc.getSVC("/examManager/saveOrUpdateQuestionOption");
          service
          .setParam("options/id", id)
          .setParam("options/optionDesc", optionDesc)
          .setParam("options/optionId", optionId)
          .setParam("options/isCorrect", isCorrect)
          .setParam("options/questionId", questionId);
          service.call(
              function (data, status) {
            	  if (data.succ == true) {
                	  $.messager.alert('提示', '保存成功!', 'info');
                	  loadOptionPage();
                      $('#tanchuang').dialog('close');
                  } else {
                	  $.messager.alert("提示信息", data.message, "error");
                  }
              }); 
        }
        
     // 删除
        function deleteQuestionOption() {
         	var row = $('#dg_cr').datagrid('getChecked');
           if (row == '') {
               $.messager.alert("提示信息", "请选择记录再删除！！！！", "error");
               return;
           }
           var idList='';
			for(var i=0;i<row.length;i++){
				var id = row[i].id;
				if(i==row.length-1){
					idList+= id;
				}else{
					idList+= id+",";
				}
			}
             $.messager.confirm("操作提示", "您确定要执行操作吗？", function (data) {
               if (data) {
               	var service = $.svc.getSVC("/examManager/deleteQuestionOption");
       	        service
       	        .setParam("options/idList", idList);
       	        service.call(
                      function (data, status) {
                   	   if (data.succ == true) {
                        	  $.messager.alert('提示', '删除成功!', 'info');
                        	  loadOptionPage();
                          } else {
                              $.messager.alert('提示', '删除失败!', 'error');
                          }
                      });
               }
           });
           
       }
        function GetRequest() {
      	  var url = location.search; //获取url中"?"符后的字串
      	   var theRequest = new Object();
      	   if (url.indexOf("?") != -1) {
      	      var str = url.substr(1);
      	      strs = str.split("&");
      	      for(var i = 0; i < strs.length; i ++) {
      	         theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
      	      }
      	   }
      	   return theRequest;
      	}

    </script>
</body>
</html>